<?php

/**
 * TranslateController
 * 
 * @package Sgit 
 * @author Juan Manuel Martinez Carrillo
 * @copyright Juan Manuel Martinez Carrillo
 * @version 2012
 * @access public
 */

class TranslateController extends Sgit_Controller_Action
{

    protected $_main_model = 'Translate';
    //protected $_main_form = 'Translate';


    public function indexAction()
    {
        
        if(!$this->_hasParam('f_locale')) $this->setParam('f_locale','en_GB');
        
        $filtros = new Sgit_Form_Filtros();
        
        $f_local = new Sgit_Form_Element_Select_Xml('Locale','f_locale');
        $f_local->setLabel('Traducciones');

        $filtros->addFormSelect($f_local);
        $values = $this->_getFiltrosValues($filtros);

        $filtros->myRender();


        $model=new  Application_Model_Translate();
 
        $locale=$values['f_locale'];
         
        if($locale)
        {
            $this->view->locale=$locale;
            $this->view->idioma=$f_local->getMultiOption($locale);
            
            $where[$locale." IS NULL OR $locale=''"]='';
           
            $this->view->rows=$model->getAll($where);
        }
    }
    
    public function borrarAction()
    {
        $this->_borrar();
    }
    
    public function editarAction()
    {
        
        $id=$this->_getParam('id');
        $valor=$this->_getParam('valor');
        $idioma=$this->_getParam('idioma');
        
        $model=new  Application_Model_Translate();
        
        
        $data[$idioma]=$valor;
        $where["id = ?"]=$id;
        
        $model->update($data,$where);
        
        $json['status'] = 'ok';
        $json['id'] = $id;
        $this->_helper->json($json);
        
    }

}
